package com.xiran.todoself.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@Slf4j
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        log.info("✅【WebConfig】CORS 配置已加载：允许 http://hdnla.asia");

        registry.addMapping("/**")
                // ✅ 只使用 allowedOriginPatterns（推荐）
                .allowedOriginPatterns("http://hdnla.asia", "https://hdnla.asia", "http://localhost:5173")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);
    }
}